package com.online.studyonline.controller;

import com.online.studyonline.pojo.Result;
import com.online.studyonline.service.LikecollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.online.studyonline.pojo.Likecollect;
@RestController
@CrossOrigin
@RequestMapping("/likecollect")
public class LikecollectController {
    @Autowired
    private LikecollectService likecollectService;
    @GetMapping("/getLikecollectList")
    //当likeType的值大于等于3时返回列表
    public Result getLikecollectList(@RequestParam("userId") int userId) {
        return Result.success(likecollectService.lambdaQuery().eq(Likecollect::getUserId, userId).ge(Likecollect::getLikeType, 3).list());
    }
    @GetMapping("/getLikecollectById")
    public Result getLikecollectById(@RequestParam("videoId") int videoId,@RequestParam("userId") int useId){
        return Result.success(likecollectService.lambdaQuery().eq(Likecollect::getVideoId, videoId).eq(Likecollect::getUserId, useId).one());
    }
    @PutMapping("/updateLikecollect")
    public Result updateLikecollect(@RequestBody Likecollect likecollect){
        return Result.success(likecollectService.updateById(likecollect));
    }
    @PostMapping("/addLikecollect")
    public Result addLikecollect(@RequestBody Likecollect likecollect){
        return Result.success(likecollectService.save(likecollect));
    }
}
